package org.jeecg.modules.wms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.wms.entity.FinishedGoodsInventory;
import org.jeecg.modules.wms.vo.InventoryQueryParam;
import org.jeecg.modules.wms.vo.InventoryStatisticsVO;
import org.jeecg.modules.wms.vo.CustomerInventoryGroup;
import org.jeecg.modules.wms.vo.HierarchicalInventoryQueryParam;

import java.util.List;

/**
 * 成品库存Mapper接口
 */
public interface FinishedGoodsInventoryMapper extends BaseMapper<FinishedGoodsInventory> {

    /**
     * 分页查询成品库存列表
     */
    IPage<FinishedGoodsInventory> queryInventoryList(Page<FinishedGoodsInventory> page, @Param("param") InventoryQueryParam param);

    /**
     * 按订单查询库存分布
     */
    List<FinishedGoodsInventory> queryInventoryByOrder(@Param("orderNo") String orderNo);

    /**
     * 按仓库统计库存
     */
    List<InventoryStatisticsVO> statisticsByWarehouse();

    /**
     * 按订单统计库存
     */
    List<InventoryStatisticsVO> statisticsByOrder();

    /**
     * 按门窗系列统计库存
     */
    List<InventoryStatisticsVO> statisticsByWindowSeries();

    /**
     * 获取库存总览统计
     */
    InventoryStatisticsVO getInventoryOverview();

    /**
     * 查询低库存预警
     */
    List<FinishedGoodsInventory> queryLowStockWarning(@Param("threshold") Integer threshold);

    /**
     * 更新库存数量
     */
    int updateInventoryQuantity(@Param("inventoryId") String inventoryId, 
                               @Param("availableQuantity") Integer availableQuantity,
                               @Param("reservedQuantity") Integer reservedQuantity,
                               @Param("totalQuantity") Integer totalQuantity);

    /**
     * 移动端成品库存查询
     */
    IPage<FinishedGoodsInventory> queryInventoryForMobile(IPage<FinishedGoodsInventory> page, @Param("param") InventoryQueryParam param);

    /**
     * 移动端分层查询成品库存（按客户-订单分组）
     */
    List<CustomerInventoryGroup> queryHierarchicalInventoryForMobile(@Param("param") HierarchicalInventoryQueryParam param);

    /**
     * Web端分层查询成品库存（按客户-订单分组，支持分页）
     */
    IPage<CustomerInventoryGroup> queryHierarchicalInventoryForWeb(IPage<CustomerInventoryGroup> page, @Param("param") HierarchicalInventoryQueryParam param);

    List<FinishedGoodsInventory> queryByOrderDetailId(@Param("orderDetailId") String orderDetailId);

    /**
     * 根据订单编号和订单明细ID查询库存信息
     */
    List<FinishedGoodsInventory> selectByOrderNoAndDetailId(@Param("orderNo") String orderNo, @Param("orderDetailId") String orderDetailId);

    /**
     * 获取成品入库单总数
     */
    Long getFinishedGoodsInboundOrderCount();

    /**
     * 获取成品出库单总数
     */
    Long getFinishedGoodsOutboundOrderCount();
}
